<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>条件渲染-案例</title>
    <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
    const root = ReactDOM.createRoot(document.getElementById('root'))

    class App extends React.Component {
        constructor(props) {
            super();
            this.state = {
                visible: true,
                displayList: ['none', 'block', 'list-item'],
                cnt : 0
            }
        }

        click1 = function () {
            this.setState({
                visible: !this.state.visible,
                cnt: this.state.cnt + 1
            })

        };
        render() {
            const { visible, displayList, cnt } = this.state;
            return (
                <div>
                    <h1>条件渲染-案例</h1>
                    <button onClick={() => this.click1()}>切换</button>
                    <div style={{display: displayList[cnt % displayList.length]}}>display</div>
                    {visible && (<div>展示</div>)}
                </div>
            )
        }
    }
    root.render(<App />);
</script>
</body>
</html>